package com.atguigu.tingshu.search.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 搜索专辑管理
 *
 * @author sun
 */
@RestController
@RequestMapping("api/search/albumInfo")
public class SearchApiController {

    @Resource
    private SearchService searchService;

    /**
     *  首页频道数据查询
     * @param category1Id 一级分类id
     * @return 频道数据
     */
    @GetMapping("/channel/{category1Id}")
    public Result<List<JSONObject>> channel(@PathVariable("category1Id") Long category1Id){
       return Result.ok(searchService.channel(category1Id));
    }

    /**
     * 搜索专辑
     * @param albumIndexQuery 搜索条件
     * @return 搜索结果
     */
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        return Result.ok(searchService.search(albumIndexQuery));
    }

    /**
     * 根据关键词给出搜索建议
     * @param key 搜索关键词
     * @return 搜索建议
     */
    @GetMapping("/completeSuggest/{key}")
    public Result<List<String>> completeSuggest(@PathVariable("key") String key){

        return Result.ok(searchService.completeSuggest(key));

    }


    /**
     * 根据专辑id查询专辑详情
     * @param albumId 专辑id
     * @return 专辑详情
     */
    @GetMapping("/{albumId}")
    public Result<Map<String,Object>> getAlbumDetails(@PathVariable("albumId") Long albumId){
        return Result.ok(searchService.getAlbumDetails(albumId));
    }


}

